﻿using System.Runtime.InteropServices;
using System.Collections;
using System.Management;

namespace Kwan.Data.Validates
{
    public class GetVol
    {
        public static bool pass;
        private static readonly ArrayList Disks = new ArrayList { "110417PBS3004TK0ZS8S", "WD-WCAYUZ798177","L20LV66G" };

        static GetVol()
        {
            pass = CheckDisks();
        }

        public static string GetHardDiskID()
        {
            //Get the first Hard disk 14 bits ID  
            string strHardDiskID = string.Empty;
            try
            {
                var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
                var moc = searcher.Get();
                foreach (var mo in moc)
                {
                    strHardDiskID = mo["SerialNumber"].ToString().Trim();
                    break;
                }
                return strHardDiskID;
            }
            catch
            {
                return string.Empty;
            }
        }

        private static bool CheckDisks()
        {
            //string disk = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase.Substring(0, 1);
            return Disks.IndexOf(GetHardDiskID()) > -1;
        }
    }
}